suppressWarnings(library(R2HTML))

# retrieve args
Args <- commandArgs(TRUE)

#Copy Args into variables
valueType <- Args[4]
meanOrResponse <- Args[5]
varianceTypeOrTreatment <- Args[6]
varianceAmntOrControl <- Args[7]
sig <- as.numeric(Args[8])

changesType <- Args[9]
changesValue <- Args[10]

plotSettingsType <- Args[11]
plotSettingsFrom <- as.numeric(Args[12])
plotSettingsTo <- as.numeric(Args[13])

graphTitle <- Args[14]

#Simons power analysis function
sipowerttest<-function(delta,sd,n,sig.level)
{
	NCP<-delta/(sd*sqrt(2/n))
	crit1<-qt((1-sig.level/2),df=(2*n-2))
	crit2<-qt((1-(1-sig.level/2)),df=(2*n-2))
	suppressWarnings(power<-1-pt(crit1,(2*n-2),NCP)+pt(crit2,(2*n-2),NCP))
}

# back to the main code
if (valueType=="DatasetValues")
{
	#Read in data
	statdata <- read.csv(Args[3], header=TRUE, sep=",")
	response <- meanOrResponse
	treatment <- varianceTypeOrTreatment
	control <- varianceAmntOrControl
} else
{
	if(meanOrResponse == "NULL")
	{
	groupMean <- 1
	} else  {
	groupMean <- as.numeric(meanOrResponse)
	}
	varianceType <- varianceTypeOrTreatment
	
	if(varianceType=="Variance")
	{
		SD <- sqrt(as.numeric(varianceAmntOrControl))
	} else
	{
		SD <- as.numeric(varianceAmntOrControl)
	}
}

powerFrom <- 0
powerTo <- 105
sampleSizeFrom <- 6
sampleSizeTo <- 15

tempChanges <-strsplit(changesValue, ",")
expectedChanges <- numeric(0)
for(i in 1:length(tempChanges[[1]])) { expectedChanges [length(expectedChanges )+1] = as.numeric(tempChanges[[1]][i]) } 
expectedChanges<-sort(expectedChanges)




#Categorised factors




if(plotSettingsType=="PowerAxis")
{
	if(valueType=="DatasetValues")
	{
		if(changesType == "Absolute")
		{
			if (treatment== "NULL")
			{


				powerFrom <- plotSettingsFrom ;
				powerTo <- plotSettingsTo ;
    			testANOVA<-aov(eval(parse(text = paste("statdata$", response)))~1)
				standev<-sqrt(anova(testANOVA)[1,3])

				sampleSizeFrom <- floor(as.numeric(power.t.test(delta=expectedChanges[length(expectedChanges)], power=((powerFrom/100)),sd=standev, sig.level=sig)[1]))

				sampleSizeTo <- ceiling(as.numeric(power.t.test(n=NULL,delta=expectedChanges[1], power=((powerTo/100)), sd=standev,sig.level=sig)[1]))
			}
			else 
			{
				treatTemp<-as.factor(eval(parse(text = paste("statdata$", treatment))))
				statdata<-cbind(statdata,treatTemp)
				powerFrom <- plotSettingsFrom ;
				powerTo <- plotSettingsTo ;
				testANOVA<-aov(eval(parse(text = paste("statdata$", response)))~statdata$treatTemp)
				standev<-sqrt(anova(testANOVA)[2,3])

				sampleSizeFrom <- floor(as.numeric(power.t.test(delta=expectedChanges[length(expectedChanges)], power=((powerFrom/100)),sd=standev, sig.level=sig)[1]))

				sampleSizeTo <- ceiling(as.numeric(power.t.test(n=NULL,delta=expectedChanges[1], power=((powerTo/100)), sd=standev,sig.level=sig)[1]))
			}
		}
		else if (changesType == "Percent")
		{
			predmeans<- unlist(lapply(split(eval(parse(text = paste("statdata$", response))),eval(parse(text= paste("statdata$", treatment)))), mean))
			contrmean<-predmeans[control]
			treatTemp<-as.factor(eval(parse(text = paste("statdata$", treatment))))
			statdata<-cbind(statdata,treatTemp)
			groupMean <- contrmean
			meanvec<-rep(groupMean,length(expectedChanges))
			temp10<-expectedChanges/100
			temp11<-meanvec*temp10
			powerFrom <- plotSettingsFrom ;
			powerTo <- plotSettingsTo ;
  			testANOVA<-aov(eval(parse(text = paste("statdata$", response)))~statdata$treatTemp)
			standev<-sqrt(anova(testANOVA)[2,3])

			sampleSizeFrom <- floor(as.numeric(power.t.test(delta=temp11[length(temp11)], power=((powerFrom/100)),sd=standev, sig.level=sig)[1]))

			sampleSizeTo <- ceiling(as.numeric(power.t.test(n=NULL,delta=temp11[1], power=((powerTo/100)), sd=standev,sig.level=sig)[1]))
		}
	}
	else if(valueType=="SuppliedValues")
	{
		if(changesType == "Absolute")
		{
			powerFrom <- plotSettingsFrom ;
			powerTo <- plotSettingsTo ;
			sampleSizeFrom <- floor(as.numeric(power.t.test(delta=expectedChanges[length(expectedChanges)],power=((powerFrom/100)),sd=SD, sig.level=sig)[1]))
			sampleSizeTo <- ceiling(as.numeric(power.t.test(n=NULL,delta=expectedChanges[1],power=((powerTo/100)), sd=SD,sig.level=sig)[1]))
		} 
		else if (changesType == "Percent")
		{
			groupMean <- as.numeric(meanOrResponse)
			meanvec<-rep(groupMean,length(expectedChanges))
			temp10<-expectedChanges/100
			temp11<-meanvec*temp10
			powerFrom <- plotSettingsFrom ;
			powerTo <- plotSettingsTo ;
			sampleSizeFrom <- floor(as.numeric(power.t.test(delta=temp11[length(temp11)], power=((powerFrom/100)),sd=SD, sig.level=sig)[1]))
			sampleSizeTo <- ceiling(as.numeric(power.t.test(n=NULL,delta=temp11[1], power=((powerTo/100)), sd=SD,sig.level=sig)[1]))
		}
	}
} else
{
	sampleSizeFrom <- plotSettingsFrom;
	sampleSizeTo <- plotSettingsTo;
}

if(graphTitle=="NULL")
{
	graphTitle <- "Power Curve"
}

#Setup the html file and associated css file
htmlFile <- sub(".csv", ".html", Args[3]); #determine the file name of the html file
.HTML.file = htmlFile
cssFile <- "r2html.css"
cssFile <- paste("'",cssFile,"'", sep="") #need to enclose in quotes when path has spaces in it
HTMLCSS(CSSfile = cssFile)

#Output HTML header
HTML.title("<bf>SilveR Power Analysis", HR=1, align="left")
HTML.title("<bf>Power curve plot", HR=2, align="left")

# Power analysis functions

# actual change using imputted values
powercurvesactual<-function(standev, diffs)
{
	legtitle<-c("- size of difference")
	legtitle2<-rep(legtitle,length(diffs))
	legtitle3<-paste(diffs,legtitle2)
	sample<-c(sampleSizeFrom:sampleSizeTo)
	temp1<-sample
	temp2<-matrix(1,nrow=length(sample),ncol=length(diffs))
	for (j in 1:length(diffs))
	{
		for(i in 1:length(sample))
		{
			test<-sipowerttest(n=sample[i], delta=diffs[j], sd=standev, sig.level=sig)
	 		temp2[i,j]=test
		}
	}
	temp3<-100*temp2
	powergraph=cbind(sample,temp3)
	
	powerPlot <- sub(".html", "powerPlot.jpg", htmlFile)
	jpeg(powerPlot)
	matplot(sample,temp3, lwd=2,pch = 1: length(temp2), ylim=c(powerFrom, powerTo), type = "l",  col = rainbow(length(diffs)), main=graphTitle, xlab = "Sample size (n)", ylab="Power (%)")
	legend("bottomright",legend= legtitle3, cex=0.6,lwd=2,lty=1:length(temp2),bg="white",col=rainbow(length(diffs)))
	void <- HTMLInsertGraph(GraphFileName=sub("[A-Z0-9a-z,:,\\\\]*App_Data[\\\\]","", powerPlot), Align="left")
}

# percentage change using iNputted values
powercurvespercentage<-function(mean,standev,pcchange)
{
	meanvec<-rep(mean,length(pcchange))
	temp10<-pcchange/100
	temp11<-meanvec*temp10
	legtitle<-c("% chg fm control")
	legtitle2<-rep(legtitle,length(temp11))
	legtitle3<-paste(pcchange,legtitle2)
	sample<-c(sampleSizeFrom:sampleSizeTo)
	temp1<-sample
	temp2<-matrix(1,nrow=length(sample),ncol=length(temp11))
	for (j in 1:length(temp11))
	{
		for(i in 1:length(sample)) 
		{
			test<-sipowerttest(n=sample[i], delta=temp11[j], sd=standev, sig.level=sig); temp2[i,j]=test
		}
	}
	temp3<-100*temp2
	powergraph=cbind(sample,temp3)
	
	powerPlot <- sub(".html", "powerPlot.jpg", htmlFile)
	jpeg(powerPlot)
	
	matplot(sample,temp3, lwd=2,pch = 1: length(temp11), ylim=c(powerFrom, powerTo), type = "l", col = rainbow(length(temp11)), main=graphTitle, xlab = "Sample size (n)", ylab="Power (%)")
	legend("bottomright",legend= legtitle3, cex=0.6,lwd=2,lty=1:length(temp11),bg="white",col=rainbow(length(temp11)))
	
	void <- HTMLInsertGraph(GraphFileName=sub("[A-Z0-9a-z,:,\\\\]*App_Data[\\\\]","", powerPlot), Align="left")
}

# actual changes using one-way ANOVA to compute variance
powercurvesactualANOVA<-function(resp, treat, diffs)
{
	testANOVA<-aov(resp~treat)
	standev<-sqrt(anova(testANOVA)[2,3])
	powercurvesactual(standev, diffs)
}

#Special case, no treatment factor selected
powercurvesactualANOVA2<-function(resp, diffs)
{
	testANOVA<-aov(resp~1)
	standev<-sqrt(anova(testANOVA)[1,3])
	powercurvesactual(standev, diffs)
}
 
# percentage change from control using one-way ANOVA to compute variance
powercurvespercentageANOVA<-function(resp, treat, ctrl, pcchange)
{
	testANOVA<-aov(resp~treat)
	standev<-sqrt(anova(testANOVA)[2,3])
	predmeans<- unlist(lapply(split(resp, treat), mean))
	contrmean<-predmeans[ctrl]
	powercurvespercentage(contrmean, standev, pcchange)
}

# Code to run the factors.
if (valueType == "SuppliedValues")
{
	if(changesType == "Absolute")
	{
		powercurvesactual(SD, expectedChanges)
	} else if (changesType == "Percent")
	{
		powercurvespercentage(groupMean, SD, expectedChanges) 
	}
} else if (valueType == "DatasetValues")
{
	if(changesType == "Absolute")
	{
		if(treatment== "NULL")
		{
			powercurvesactualANOVA2(eval(parse(text = paste("statdata$", response))), expectedChanges)
		}
		else {
			treatTemp<-as.factor(eval(parse(text = paste("statdata$", treatment))))
			statdata<-cbind(statdata,treatTemp)
			powercurvesactualANOVA(eval(parse(text = paste("statdata$", response))), statdata$treatTemp, expectedChanges)
		}
	} else if (changesType == "Percent")
	{
		treatTemp<-as.factor(eval(parse(text = paste("statdata$", treatment))))
		statdata<-cbind(statdata,treatTemp)
		powercurvespercentageANOVA(eval(parse(text = paste("statdata$", response))), statdata$treatTemp, eval(control), expectedChanges)
	}
}

HTML.title("<bf> ", HR=2, align="left")
HTML.title("Note: Power calculations made by SilveR assume the statistical analysis will be performed using the two sample t-test. 
This may lead to slightly conservative estimates of sample sizes and statistical power.", HR=0, align="left")
HTML.title("<bf> ", HR=2, align="left")
HTML.title("<bf>Selected results", HR=2, align="left")


# Text if Power is selected
if(plotSettingsType=="PowerAxis")
{
	#Selected results for user defined parameters
	if (valueType == "SuppliedValues")
	{
		if(changesType == "Absolute")
		{
			sample<-c(sampleSizeFrom, floor((sampleSizeFrom+sampleSizeTo)/2), sampleSizeTo)
			text1<-c(" ")
			for (j in 1:1)
			{
				for(i in 1:length(sample)) 
					{test<-sipowerttest(n=sample[i], delta=expectedChanges[j], sd=SD, sig.level=sig)
					pow<-format(round(100*test,0),nsmall=0)
					text1<-paste(text1, "Assuming the significance level is set at ", sep="")
					text1<-paste(text1, 100*sig, sep="")
					text1<-paste(text1, "%, and the sample size is ", sep="")
					text1<-paste(text1, sample[i], sep="")
					text1<-paste(text1, ", the power of the experiment to detect a biologically relevant effect of size ", sep="")
					text1<-paste(text1, expectedChanges[j], sep="")
					text1<-paste(text1, " is ", sep="")
					text1<-paste(text1, pow, sep="")
					text1<-paste(text1, "%.  ", sep="")
					HTML.title(text1, HR=0, align="left")
					HTML.title("<bf> ", HR=2, align="left")
					text1<-c(" ")
				}
			}
		}
		if(changesType == "Percent")
		{
			sample<-c(sampleSizeFrom, floor((sampleSizeFrom+sampleSizeTo)/2), sampleSizeTo)
			text1<-c(" ")
			groupMean <- as.numeric(meanOrResponse)
			meanvec<-rep(groupMean,length(expectedChanges))
			temp10<-expectedChanges/100
			temp11<-meanvec*temp10
			for (j in 1:1)
			{
				for(i in 1:length(sample)) 
					{test<-sipowerttest(n=sample[i], delta=temp11[j], sd=SD, sig.level=sig)
					pow<-format(round(100*test,0),nsmall=0)
					text1<-paste(text1, "Assuming the significance level is set at ", sep="")
					text1<-paste(text1, 100*sig, sep="")
					text1<-paste(text1, "%, and the sample size is " , sep="") 
					text1<-paste(text1, sample[i], sep="")
					text1<-paste(text1, ", the power of the experiment to detect a biologically relevant ", sep="")
					text1<-paste(text1, expectedChanges[j], sep="")
					text1<-paste(text1, "% change from control is ", sep="")
					text1<-paste(text1, pow, sep="")
					text1<-paste(text1, "%.  ", sep="")
					HTML.title(text1, HR=0, align="left")
					HTML.title("<bf> ", HR=2, align="left")
					text1<-c(" ")
				}
			}
		}
	} 
	else if (valueType == "DatasetValues")
	{
		if(changesType == "Absolute")
		{
			sample<-c(sampleSizeFrom, floor((sampleSizeFrom+sampleSizeTo)/2), sampleSizeTo)
			text1<-c(" ")
			if(treatment== "NULL")
			{
				testANOVA<-aov(eval(parse(text = paste("statdata$", response, "~1"))))
				standev<-sqrt(anova(testANOVA)[1,3])
			}
			else {
				treatTemp<-as.factor(eval(parse(text = paste("statdata$", treatment))))
				statdata<-cbind(statdata,treatTemp)
				testANOVA<-aov(eval(parse(text = paste("statdata$", response)))~statdata$treatTemp)
				standev<-sqrt(anova(testANOVA)[2,3])
			}
			for (j in 1:1)
			{
				for(i in 1:length(sample)) 
					{test<-sipowerttest(n=sample[i], delta=expectedChanges[j], sd=standev, sig.level=sig)
					pow<-format(round(100*test,0),nsmall=0)
					text1<-paste(text1, "Assuming the significance level is set at ", sep="")
					text1<-paste(text1, 100*sig, sep="")
					text1<-paste(text1, "%, and the sample size is ", sep="")
					text1<-paste(text1, sample[i], sep="")
					text1<-paste(text1, ", the power of the experiment to detect a biologically relevant effect of size ", sep="")
					text1<-paste(text1, expectedChanges[j], sep="")
					text1<-paste(text1, " is ", sep="")
					text1<-paste(text1, pow, sep="")
					text1<-paste(text1, "%.  ", sep="")
					HTML.title(text1, HR=0, align="left")
					HTML.title("<bf> ", HR=2, align="left")
					text1<-c(" ")
				}
			}
		}
		if(changesType == "Percent")
		{
			sample<-c(sampleSizeFrom, floor((sampleSizeFrom+sampleSizeTo)/2), sampleSizeTo)
			text1<-c(" ")
			treatTemp<-as.factor(eval(parse(text = paste("statdata$", treatment))))
			statdata<-cbind(statdata,treatTemp)
			testANOVA<-aov(eval(parse(text = paste("statdata$", response)))~statdata$treatTemp)
			standev<-sqrt(anova(testANOVA)[2,3])
			predmeans<- unlist(lapply(split(eval(parse(text = paste("statdata$", response))),eval(parse(text= paste("statdata$", treatment)))), mean))			

			contrmean<-predmeans[control]
			groupMean <- contrmean
			meanvec<-rep(groupMean,length(expectedChanges))
			temp10<-expectedChanges/100
			temp11<-meanvec*temp10
			for (j in 1:1)
			{
				for(i in 1:length(sample)) 
					{test<-sipowerttest(n=sample[i], delta=temp11[j], sd=standev, sig.level=sig)
					pow<-format(round(100*test,0),nsmall=0)
					text1<-paste(text1, "Assuming the significance level is set at ", sep="")
					text1<-paste(text1, 100*sig, sep="")
					text1<-paste(text1, "%, and the sample size is " , sep="") 
					text1<-paste(text1, sample[i], sep="")
					text1<-paste(text1, ", the power of the experiment to detect a biologically relevant ", sep="")
					text1<-paste(text1, expectedChanges[j], sep="")
					text1<-paste(text1, "% change from control is ", sep="")
					text1<-paste(text1, pow, sep="")
					text1<-paste(text1, "%.  ", sep="")
					HTML.title(text1, HR=0, align="left")
					HTML.title("<bf> ", HR=2, align="left")
					text1<-c(" ")
					}
				}
			}
		}
	} else
	{
	#Selected results for user defined parameters
	if (valueType == "SuppliedValues")
	{
		if(changesType == "Absolute")
		{
			sample<-c(sampleSizeFrom, floor((sampleSizeFrom+sampleSizeTo)/2), sampleSizeTo)
			text1<-c(" ")
			for (j in 1:1)
			{
				for(i in 1:length(sample)) 
					{test<-sipowerttest(n=sample[i], delta=expectedChanges[j], sd=SD, sig.level=sig)
					pow<-format(round(100*test,0),nsmall=0)
					text1<-paste(text1, "Assuming the significance level is set at ", sep="")
					text1<-paste(text1, 100*sig, sep="")
					text1<-paste(text1, "%, and the sample size is ", sep="")
					text1<-paste(text1, sample[i], sep="")
					text1<-paste(text1, ", the power of the experiment to detect a biologically relevant effect of size ", sep="")
					text1<-paste(text1, expectedChanges[j], sep="")
					text1<-paste(text1, " is ", sep="")
					text1<-paste(text1, pow, sep="")
					text1<-paste(text1, "%.  ", sep="")
					HTML.title(text1, HR=0, align="left")
					HTML.title("<bf> ", HR=2, align="left")
					text1<-c(" ")
					}
				}
			}
		if(changesType == "Percent")
		{
			sample<-c(plotSettingsFrom, floor((plotSettingsFrom+plotSettingsTo)/2), plotSettingsTo)
			text1<-c(" ")
			groupMean <- as.numeric(meanOrResponse)
			meanvec<-rep(groupMean,length(expectedChanges))
			temp10<-expectedChanges/100
			temp11<-meanvec*temp10
			for (j in 1:1)
			{
				for(i in 1:length(sample)) 
					{test<-sipowerttest(n=sample[i], delta=temp11[j], sd=SD, sig.level=sig)
					pow<-format(round(100*test,0),nsmall=0)
					text1<-paste(text1, "Assuming the significance level is set at ", sep="")
					text1<-paste(text1, 100*sig, sep="")
					text1<-paste(text1, "%, and the sample size is " , sep="") 
					text1<-paste(text1, sample[i], sep="")
					text1<-paste(text1, ", the power of the experiment to detect a biologically relevant ", sep="")
					text1<-paste(text1, expectedChanges[j], sep="")
					text1<-paste(text1, "% change from control is ", sep="")
					text1<-paste(text1, pow, sep="")
					text1<-paste(text1, "%.  ", sep="")
					HTML.title(text1, HR=0, align="left")
					HTML.title("<bf> ", HR=2, align="left")
					text1<-c(" ")
					}
				}
			}
		} 
		else if (valueType == "DatasetValues")
		{
		if(changesType == "Absolute")
		{
			sample<-c(plotSettingsFrom, floor((plotSettingsFrom+plotSettingsTo)/2), plotSettingsTo)
			text1<-c(" ")
			if(treatment== "NULL")
			{
				testANOVA<-aov(eval(parse(text = paste("statdata$", response, "~1"))))
				standev<-sqrt(anova(testANOVA)[1,3])
			}
			else {
				treatTemp<-as.factor(eval(parse(text = paste("statdata$", treatment))))
				statdata<-cbind(statdata,treatTemp)
				testANOVA<-aov(eval(parse(text = paste("statdata$", response)))~statdata$treatTemp)
				standev<-sqrt(anova(testANOVA)[2,3])
			}
			for (j in 1:1)
			{
				for(i in 1:length(sample)) 
					{test<-sipowerttest(n=sample[i], delta=expectedChanges[j], sd=standev, sig.level=sig)
					pow<-format(round(100*test,0),nsmall=0)
					text1<-paste(text1, "Assuming the significance level is set at ", sep="")
					text1<-paste(text1, 100*sig, sep="")
					text1<-paste(text1, "%, and the sample size is ", sep="")
					text1<-paste(text1, sample[i], sep="")
					text1<-paste(text1, ", the power of the experiment to detect a biologically relevant effect of size ", sep="")
					text1<-paste(text1, expectedChanges[j], sep="")
					text1<-paste(text1, " is ", sep="")
					text1<-paste(text1, pow, sep="")
					text1<-paste(text1, "%.  ", sep="")
					HTML.title(text1, HR=0, align="left")
					HTML.title("<bf> ", HR=2, align="left")
					text1<-c(" ")
					}
				}
			}
		if(changesType == "Percent")
		{
			sample<-c(plotSettingsFrom, floor((plotSettingsFrom+plotSettingsTo)/2), plotSettingsTo)
			text1<-c(" ")
			treatTemp<-as.factor(eval(parse(text = paste("statdata$", treatment))))
			statdata<-cbind(statdata,treatTemp)		
			testANOVA<-aov(eval(parse(text = paste("statdata$", response)))~statdata$treatTemp)
			standev<-sqrt(anova(testANOVA)[2,3])
			predmeans<- unlist(lapply(split(eval(parse(text = paste("statdata$", response))),eval(parse(text= paste("statdata$", treatment)))), mean))			
			contrmean<-predmeans[control]
			groupMean <- contrmean
			meanvec<-rep(groupMean,length(expectedChanges))
			temp10<-expectedChanges/100
			temp11<-meanvec*temp10
			for (j in 1:1)
			{
				for(i in 1:length(sample)) 
					{test<-sipowerttest(n=sample[i], delta=temp11[j], sd=standev, sig.level=sig)
					pow<-format(round(100*test,0),nsmall=0)
					text1<-paste(text1, "Assuming the significance level is set at ", sep="")
					text1<-paste(text1, 100*sig, sep="")
					text1<-paste(text1, "%, and the sample size is " , sep="") 
					text1<-paste(text1, sample[i], sep="")
					text1<-paste(text1, ", the power of the experiment to detect a biologically relevant ", sep="")
					text1<-paste(text1, expectedChanges[j], sep="")
					text1<-paste(text1, "% change from control is ", sep="")
					text1<-paste(text1, pow, sep="")
					text1<-paste(text1, "%.  ", sep="")
					HTML.title(text1, HR=0, align="left")
					HTML.title("<bf> ", HR=2, align="left")
					text1<-c(" ")
					}
				}
			}
		}
	} 

HTML.title("<bf>Definitions", HR=2, align="left")
HTML.title("Power: The chance of achieving a statistically significant test result from running an experiment, assuming there is a real biological effect to find.", HR=0, align="left")
HTML.title("<bf> ", HR=2, align="left")
HTML.title("Significance level: The chance that the experiment will give a false-positive result.", HR=0, align="left")
HTML.title("<bf> ", HR=2, align="left")
HTML.title("Biologically relevant effect: The size of effect that is of scientific interest.", HR=0, align="left")

HTML.title("<bf>Statistical references", HR=2, align="left")
HTML.title("Harrison, DA and Brady, AR (2004). Sample size and power calculations using the noncentral t-distribution. The Stata Journal, 4(2), 142-153.", HR=0, align="left")

HTMLbr()
HTML.title("<bf>R references", HR=2, align="left")

HTML.title("<bf> ", HR=2, align="left")
	HTML.title("<bf>   R Development Core Team (2008). R: A language and environment for
	statistical computing. R Foundation for Statistical Computing,
	Vienna, Austria. ISBN 3-900051-07-0, URL http://www.R-project.org.", HR=0, align="left")

HTML.title("<bf> ", HR=2, align="left")
	HTML.title("<bf>    Lecoutre, Eric (2003). The R2HTML Package. R News, Vol 3. N. 3, Vienna, Austria.
	", HR=0, align="left")
